﻿
@{
    ViewBag.Title = "Material_rebate";
}

@section styles{
    <style>
        th {
            text-align: center;
        }

        td {
            text-align: center;
        }

        #bigdiv {
            overflow: scroll;
            margin-left: 15px;
            height: 450px;
        }

        table {
            width: 100%;
        }
    </style>
}
<from>
    <fieldset>
        <label id="HJ_CP_sqd" class="len">物料回价</label>
        <div id="HJ_CL_TJ">提交</div>
        <div id="HJ_CL_HJ">开始核价</div>
        <div id="bigdiv">
            <table>
                <thead>
                    <tr>
                        <th><input type="checkbox" id="HJ_CL_s_all" /></th>
                        <th>物料名称</th>
                        <th>料号</th>
                        <th>供应商</th>
                        <th>供应商回价</th>
                    </tr>
                </thead>
                <tbody id="HJ_CL_TB">
                </tbody>
            </table>
        </div>
    </fieldset>
</from>


@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            get_inf()
            Bulk_Callback()
            KSHJ()
            //获取需要询价的物料信息
            function get_inf() {
                $.ajax({
                    url: '/Procure/Material_rebate',
                    type: 'GET',
                    data: { "state": 1 },
                    success: function (data) {
                        createTR(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            //打印物料信息
            function createTR(data) {
                $('#HJ_CL_TB tr').remove();
                $.each(data, function (i, item) {
                    var $tr = $(`
                                <tr>
                                    <td><input type="checkbox" name="HJ_CL_TJ_check"/></td>
                                    <td id="Inf_id" style="display:none">${item.Inf_id}</td>
                                    <td>${item.Inf_wu}</td>
                                    <td>${item.Inf_liao}</td>
                                    <td>${item.Inf_gong}</td>
                                    <td><input type="number" name="HJ_CL_n_HJ"/></td>
                                </tr>

                            `);
                    $('#HJ_CL_TB').append($tr);
                })
            }
            //批量提交供应商回价
            function Bulk_Callback() {
                $(document).on("click", "#HJ_CL_TJ", function () {
                    var HJ_jg = []
                    var hang = $("input[name='HJ_CL_TJ_check']:checked").parent().length
                    if (hang <= 0) {
                        alert("请选择要恢复的价格")
                    }
                    else {
                        $("input[name='HJ_CL_TJ_check']:checked").parent().parent().each(function (i, item) {
                            HJ_jg.push({
                                Inf_id: $("td[id='Inf_id']", item).text(),
                                Inf_zhuang: "已提交",
                                Inf_huiP: $("input[name='HJ_CL_n_HJ']", item).val()
                            })
                        })
                        console.log("共" + HJ_jg.length + "数据");
                        console.log(HJ_jg);
                        $.ajax({
                            url: "/Procure/Modify_All_GYS_HJ",
                            type: "POST",
                            data: JSON.stringify(HJ_jg),
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            success: function (text) {
                                if (text > 0) {
                                    alert("添加成功" + text.msg);
                                    get_inf()
                                } else {
                                    alert("添加失败" + text.msg);
                                    get_inf()
                                }

                            },
                            error: function (text) {
                                alert("系统错误" + text);
                            }
                        })
                    }
                })
            }
            //全选的方法
            function select_all() {
                $(document).on("click", "#HJ_CL_s_all", function (e) {
                    if ($(e.target).attr("checked", true)) {
                        console.log($(e.target))
                        $("input[name='HJ_CL_TJ_check']").attr("checked", true)
                    }
                    else {
                        console.log($(e.target))
                        $("input[name='HJ_CL_TJ_check']").attr("checked", false)
                    }
                })
            }
            function KSHJ() {
                $(document).on("click", "#HJ_CL_HJ", function () {
                    window.location.href = "/Procure/pricing_New_2"
                })
            }
        })
    </script>
}